<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';	
include '../../content-accountant/invoicetax.php';
$tonggiacungcap=0;
$tongthue=0;
$tongtien=0;
$loi='';
$status=$_REQUEST['status'];
if($status==0){
	$l_ngaygiaodich=$l_ngaygiaodich0;
	$l_ngayphathanh=$l_ngayphathanh0;	
	$l_thoigiangiaodich=$l_thoigiangiaodich0;
}
if($status==1){
	$l_ngaygiaodich=$l_ngaygiaodich1;
	$l_ngayphathanh=$l_ngayphathanh1;	
	$l_thoigiangiaodich=$l_thoigiangiaodich1;
}
$_SESSION['invoice_arr']=array();
if(isset($_REQUEST['type'])){
	if($_REQUEST['type']=="del"){
		if(isset($_REQUEST['id'])){
			try{
				$sql ="delete from or_order_tax where or_order_tax.orderid=".$_REQUEST['id'];
				mysql_query($sql);
				$loi="l_xoathanhcong";
			}catch(exception $e){
				$loi=$e->getMessage();
			}
		}
	}else if($_REQUEST['type']=="up"){
		try{
			$sl=count($_SESSION['input_invoice']);
			if($sl>0){
				for($i=0;$i<$sl;$i++){
					$inobject= unserialize (serialize ($_SESSION['input_invoice'][$i]));
					$vdate=$inobject->oryear."-".$inobject->ormonth."-".$inobject->orday;
					$sql="UPDATE or_order_tax set or_order_tax.order_time='".$vdate."',
					or_order_tax.order_cusname='".$inobject->cusname."',
					or_order_tax.order_content='".$inobject->order_content."',
					or_order_tax.order_quantity=".$inobject->order_quantity.",
					or_order_tax.order_supply_rice=".$inobject->order_suplly_rice.",
					or_order_tax.order_tax=".$inobject->order_tax.",
					or_order_tax.order_total=".$inobject->order_total.",
					or_order_tax.user_create='".$_SESSION['IDEmployee']."',
					or_order_tax.date_create=now(),
					or_order_tax.order_time_transaction='".$inobject->order_time_transaction."' 
					where or_order_tax.orderid=".$inobject->orderid;
					mysql_query($sql);
				}
				$loi='l_capnhatthanhcong';
			}
		}catch(exception $e){
			$loi=$e->getMessage();
		}
	}
}else{
	if(isset($_SESSION['input_invoice'])){
		$sl=count($_SESSION['input_invoice']);
		if($sl>0){
			$sql ="INSERT into or_order_tax (order_time,order_cusname,order_content,order_quantity,order_supply_rice,order_tax,order_total,order_time_transaction,user_create,date_create,is_status) values ";
			$tem="";
			for($i=0;$i<$sl;$i++){
				$inobject= unserialize (serialize ($_SESSION['input_invoice'][$i]));
					if($inobject->order_time_transaction=="")
						$date="'null'";
					else
						$date="'".$inobject->order_time_transaction."'";
						
					$order_time=$inobject->oryear."-".$inobject->ormonth."-".$inobject->orday;
					if($tem==""){
						$tem="('".$order_time."','".$inobject->cusname."','".$inobject->order_content."',".$inobject->order_quantity.",".$inobject->order_suplly_rice.",".$inobject->order_tax.",".$inobject->order_total.",".$date.",'".$_SESSION['IDEmployee']."',now(),".$status.")";
					}else{
						$tem .=",('".$order_time."','".$inobject->cusname."','".$inobject->order_content."',".$inobject->order_quantity.",".$inobject->order_suplly_rice.",".$inobject->order_tax.",".$inobject->order_total.",".$date.",'".$_SESSION['IDEmployee']."',now(),".$status.")";
					}

				}
			}
			if($tem !=""){
				try{
					
					mysql_query($sql.$tem);
					//echo $sql.$tem;
					$loi="l_themthanhcong";
				}catch (exception $e){
					$loi=$e->getMessage();
				}
			}else{
				$loi=$l_khongluu;
			}
		}
}


$sqlinvoice=mysql_query("SELECT or_order_tax.* from or_order_tax where month(or_order_tax.order_time)='".$_REQUEST['thang']."' and year(or_order_tax.order_time)='".$_REQUEST['nam']."' and is_status='".$status."' ORDER BY or_order_tax.order_time,or_order_tax.order_time_transaction asc");
?>
<table cellpadding="0" cellspacing="1" width="100%" border="0" class="ftable">
		            <tr >
		                <th style="width:10px"></th>
		                <th style="width:10px"><?=$l_no?></th>
		                <th style="width:30px"><?=$l_month?></th>
		                <th style="width:30px"><?=$l_days?></th>
		                <th style="width:220px"><?=$l_customer?></th>
		                <th style="width:40%"><?=$l_product_item?></th>
		                <th style="width:50px;"><?=$l_quantity?></th>
		                <th style="width:90px"><?=$l_Supply_price?></th>
		                <th style="width:90px"><?=$l_vat?></th>
		                <th style="width:90px"><?=$l_amount?></th>
		                <th style="width:90px"><?=$l_thoigiangiaodich?></th> 

		            </tr>
		            <?php 
		            if(mysql_num_rows($sqlinvoice)>0){
		            	$soluonggiaodich=0;
		            	$tonggiacungcap=0;
		            	$tongthue=0;
		            	$tongtien=0;
		            	$vitri=0;
		            	while($rin=mysql_fetch_array($sqlinvoice)){
		            		$inobject= new invoicetax();
		            		$ktdate=getdate(strtotime($rin[order_time]));
		            		$inobject->Instance($rin[orderid],$rin[order_time],$ktdate[mon],$ktdate[mday],$ktdate[year],$rin[order_cus],$rin[order_content],$rin[order_quantity],$rin[order_supply_rice],$rin[order_tax],$rin[order_total],$rin[order_time_transaction],$rin[is_status],$rin[user_create],$rin[date_create] );
		            		$inobject->setCusname($rin[order_cusname]);
		            		if($vitri % 2 ==0){
	            			?><tr class="coltr2" style="padding:3px"><?php 
		            		}else{
	            			?><tr style="padding:3px"><?php 
		            		}
		            		?>
		            		<td>
			                	<img onclick="delOneRow(<?=$inobject->orderid?>,<?=$status?>);" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?php echo $l_delete;?>" />
			                </td>
		            		<td style="padding: 5px;cursor:pointer;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 20px"><?=($vitri+1)?></p></td>
			                <td style="cursor:pointer;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 20px"><?=$inobject->ormonth?></p></td>
			                <td style="cursor:pointer;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 20px"><?=$inobject->orday?></p></td>
			                <td style="cursor:pointer;text-align:left;padding-left:3px;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 220px"><?php echo $inobject->cusname;?></p></td>
			                <td style="cursor:pointer;text-align:left;padding-left:3px;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="min-width: 250px"><?=$inobject->order_content?></p></td>
			                <td style="cursor:pointer;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 30px"><?=number_format($inobject->order_quantity)?></p></td>
			                <td style="cursor:pointer;text-align:right;padding-right:3px;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 90px"><?=number_format($inobject->order_suplly_rice)?></p></td>
			                <td style="cursor:pointer;text-align:right;padding-right:3px;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 90px"><?=number_format($inobject->order_tax)?></p></td>
			                <td style="cursor:pointer;text-align:right;padding-right:3px;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 90px"><?=number_format($inobject->order_total)?></p></td>
			                <td style="cursor:pointer;" onclick="editOneRow(<?=$vitri?>,<?=$inobject->orderid?>,<?=$status?>)"><p style="width: 80px"><?=$inobject->order_time_transaction?></p></td>
		            		<?php 
		            		$vitri++;
		            		$soluonggiaodich++;
		            		$tonggiacungcap +=$inobject->order_suplly_rice;
		            		$tongthue +=$inobject->order_tax;
		            		$tongtien +=$inobject->order_total;
		            		?></tr><?php 
		            		$_SESSION['invoice_arr'][$rin[orderid]]=$inobject;
		            	}
		            }else{
		            ?>
		            <tr><td colspan="11" style="height:30px;text-align:left;padding-left:20px;"><?php echo $l_list_emplty;?></td></tr>
		            <?php }?>
		            <tr class="coltr2" style="height:30px;font-weight:bold;">
		                <td colspan="5"><?php echo $l_month;?> : <font color="red"><?php echo $_REQUEST['thang']?></font>  -  <?php echo $l_co;?>  <font color="blue"><?php echo number_format($soluonggiaodich);?></font> <?php echo $l_giaodich;?></td>
		                <td></td>
		                <td></td>
		                <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap);?></td>
		                <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue);?></td>
		                <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien);?></td>
		                <td></td>
		            </tr>            
		        </table>   
		        <input type="hidden" value="<?=$loi?>" id="convoi" /> 
		        <?php mysql_close($connection);?>